package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-03-21 21:47
 */
public class QLint637 {
    public boolean validWordAbbreviation(String word, String abbr) {
        int i = 0, j = 0;
        int m = word.length(), n = abbr.length();
        while(i < m && j < n) {
            if(!Character.isDigit(abbr.charAt(j))) {
                if(word.charAt(i) != abbr.charAt(j)) {
                    return false;
                }
                i++;
                j++;
            } else {
                int num = 0;
                if(abbr.charAt(j) == '0') {
                    return false;
                }

                while(j < n && Character.isDigit(abbr.charAt(j))) {
                    num = num * 10 + Integer.parseInt(abbr.charAt(j) + "");
                    j++;
                }

                i += num;
                if(i > m) {
                    return false;
                }
            }
        }

        if(i == m && j == n) {
            return true;
        }

        return false;
    }
}
